#ifndef MAP_H
#define MAP_H

#include "tile.h" 
#include "player.h"
#include "animation.h"

class map{
	public:
	
	map(int mapWidth, int mapHeight);
	~map();
	void drawMapBackground();	
	void drawMapForeground();
	void putTilesInto2DVector();
	void cameraUpdate(int player_x, int player_y);
	void putTileIntoVector(tile *tileinput);
	int mapWidth;
	int mapHeight;
	int screenWidth;
	int screenHeight;
	void addAni(animation* ani);
	
	animation * ani;
	
	vector <ALLEGRO_BITMAP *> building;	
	vector <tile *> tileVector;
	vector<vector<int> > tile2DVector;
	
	int camera_x;
	int camera_y;
	private:
};

map::map(int mapWidth, int mapHeight){
	screenWidth = 640;
	screenHeight = 480;
	this->mapWidth = mapWidth;
	this->mapHeight = mapHeight;
	camera_x=0;
	camera_y=0;
}

map::~map(){
}

void map::addAni(animation* ani){
	this->ani=ani;
}

void map::drawMapBackground(){
	for(int i = 0; i < screenWidth/16; i++)
	{
		for(int j = 0; j < screenHeight/16; j++)
			al_draw_bitmap(tileVector[tile2DVector[i][j]]->tileImage,i * 16, j * 16 ,0);
	}
}

void map::drawMapForeground(){
	
}

void map::cameraUpdate(int player_x, int player_y){
	camera_x = -(screenWidth/2)+(player_x );
	camera_y = -(screenHeight/2)+(player_y );  
	
	if(camera_x < 0)
		camera_x = 0;
	if(camera_y < 0)
		camera_y = 0;
}

//puts a tile into a vector
void map::putTileIntoVector(tile *tileinput){
	tileVector.push_back(tileinput);
}

//creates the map 2D vector with integer values of the tile id
void map::putTilesInto2DVector(){
	for(int i = 0; i < screenWidth/16; i++ ){
		tile2DVector.push_back(vector<int>());
		for(int j = 0; j< screenHeight/16; j++)
		{   
			if(i==0|| i== (screenWidth/16 - 1)|| j == 0 || j == (screenHeight/16 -1))
			tile2DVector[i].push_back(1);
			else tile2DVector[i].push_back(0);
		}
	}
	tile2DVector[20][15]=1;
	tile2DVector[20][16]=1;
	tile2DVector[20][17]=1;
	tile2DVector[20][18]=1;
	tile2DVector[20][19]=1;
	tile2DVector[20][20]=1;
	tile2DVector[20][21]=1;
	tile2DVector[20][22]=1;
	tile2DVector[20][23]=1;
	tile2DVector[21][15]=1;
	tile2DVector[21][16]=1;
	tile2DVector[21][17]=1;
	tile2DVector[21][18]=1;
	tile2DVector[21][19]=1;
	tile2DVector[21][20]=1;
	tile2DVector[21][21]=1;
	tile2DVector[21][22]=1;
	tile2DVector[21][23]=1;

	tile2DVector[17][23]=1;
	tile2DVector[16][23]=1;
	tile2DVector[15][23]=1;
	tile2DVector[14][23]=1;
	tile2DVector[13][23]=1;
	tile2DVector[12][23]=1;
	tile2DVector[11][23]=1;
	tile2DVector[10][23]=1;
	tile2DVector[20][22]=1;
	tile2DVector[19][22]=1;
	tile2DVector[18][22]=1;
	tile2DVector[17][22]=1;
	tile2DVector[16][22]=1;
	tile2DVector[15][22]=1;
	tile2DVector[14][22]=1;
	tile2DVector[12][22]=1;
	tile2DVector[11][22]=1;
	tile2DVector[10][23]=1;
	
	tile2DVector[20][9]=1;
	tile2DVector[20][8]=1;
	tile2DVector[20][7]=1;
	tile2DVector[20][6]=1;
	tile2DVector[20][5]=1;
	tile2DVector[20][4]=1;
	tile2DVector[20][3]=1;
	tile2DVector[20][2]=1;
}
#endif
